﻿using System;
using System.Linq;
using System.Transactions;
using NUnit.Framework;
using ProjetoComperio.BusinessLogicLayer;
using ProjetoComperio.DataLayer.Entities;
using ProjetoComperio.Test.FakeData;

namespace ProjetoComperio.Test.BusinessLogicLayer
{
    [TestFixture]
    public class EventBLLTest
    {
        EventBLL eventBLL;
        [TestFixtureSetUp]
        public void TestFixtureSetUp()
        {
            eventBLL = new EventBLL();
        }

        [SetUp]
        public void SetUp()
        {
            eventBLL.InitializeDataContext(new FakeComperioEntitiesDataModel());
        }

        [Test]
        public void TestRetrieveEvents()
        {
            Assert.AreEqual(2, eventBLL.RetrieveEvents().Count());
        }

        [Test]
        [Category("lazy")]
        public void TestCreate_Valid()
        {
            eventBLL = new EventBLL();
            var fakeStudent = StudentBLLTest.CreateFakeStudent();
            var validEvent = GenerateValidEvent();
                
            using (TransactionScope transactionScope = new TransactionScope())
            {
                new StudentBLL().Create(fakeStudent,"teste_anything","anyPassWord1234");
                validEvent.AcademicPerson = fakeStudent;
                eventBLL.Create(validEvent);

                Assert.IsNotNull(eventBLL.RetrieveEvent(validEvent.ContributionID));
            }
        }

        private Event GenerateValidEvent()
        {
            Event _event = new Event();
            _event.Author = "H Ramos";
            _event.AuthorDescription = "Just more one";
            _event.ContributionID = 872671;
            _event.Description = "Another IT event";
            _event.Details = "Details";
            _event.EndDate = DateTime.Now.AddDays(2);
            _event.StartDate = DateTime.Now;
            _event.Location = "Location";
            _event.RegisterDate = DateTime.Now;
            _event.SourceInfo = "www.higorcesar.com.br";
            _event.Subject = "IT";
            _event.Title = "IT Design";
            return _event;

        }

    }
}
